//
//  CinemaViewController.m
//  12.30_homework_豆瓣电影MVC
//
//  Created by dllo on 15/12/30.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import "CinemaViewController.h"
#import "CinemaCell.h"
#import "CinemaModel.h"

@interface CinemaViewController () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;

@property (nonatomic, retain) NSMutableArray *arrModel;

@end

@implementation CinemaViewController

- (void)dealloc {
    [_tableView release];
    [_arrModel release];
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"影院";
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:(UITableViewStylePlain)];
    [self.view addSubview:_tableView];
    [_tableView release];
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [self.tableView registerClass:[CinemaCell class] forCellReuseIdentifier:@"cell"];
    
//    [_tableView registerNib:[UINib nibWithNibName:@"CinemaCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"cell"];
    
    [self dataHandle];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _arrModel.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CinemaCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    CinemaModel *cinemaModel = _arrModel[indexPath.row];
    
    cell.cinemaName.text = cinemaModel.cinemaName;
    cell.address.text = cinemaModel.address;
    cell.telephone.text = cinemaModel.telephone;
    
//    cell.MyCinemaName.text = cinemaModel.cinemaName;
//    cell.MyAddress.text = cinemaModel.address;
//    cell.MyTelephone.text = cinemaModel.telephone;
    
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 200;
}

- (void)dataHandle {
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"cinema" ofType:@"plist"];
    NSArray *arrData = [NSArray arrayWithContentsOfFile:path];
    
    self.arrModel = [NSMutableArray array];
    for (NSDictionary *dic in arrData) {
        CinemaModel *cinemaModel = [CinemaModel cinemaModel];
        [cinemaModel setValuesForKeysWithDictionary:dic];
        [_arrModel addObject:cinemaModel];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
